package org.gdpu.service.impl;

import org.gdpu.base.DaoSupport;
import org.gdpu.model.ResourceCategory;
import org.gdpu.service.ResourceCategoryService;
import org.gdpu.util.fileConverter.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-4
 * Time: 下午1:21
 * To change this template use File | Settings | File Templates.
 */
@Service
@Transactional
public class ResourceCategoryServiceImpl extends DaoSupport<ResourceCategory> implements ResourceCategoryService {

    @Override
    public List<ResourceCategory> allCategory() {
        return (List<ResourceCategory>)this.getScrollData(ResourceCategory.class).getResultList();
    }

    @Override
    public String matchSufix(String fileName, String categoryName) {
        String sufix = FileUtils.getFileSufix(fileName);
        String sufixs = getCategorySufixByName(categoryName);
        boolean match = FileUtils.isSufix(sufix,sufixs);
        if(match){
            return "";
        }else {
            return "类型不匹配,只支持"+ sufixs + "格式";
        }
    }

    @Override
    public String getCategorySufixByName(String categoryName) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("name", categoryName);
        ResourceCategory category = (ResourceCategory) this.findSpecialObject(ResourceCategory.class, params);
        return category.getSufix();
    }
}
